package com.mvc4g.example.mockup.client.view.views;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.client.Event;
import com.mvc4g.example.mockup.client.bean.AboutBean;
import com.mvc4g.example.mockup.client.view.widgets.AboutWidget;
import com.mvc4g.example.mockup.client.view.widgets.IntroductionWidget;



public class AboutView extends AbstractView {

	private AboutWidget about = null;
	private IntroductionWidget introduction = null;

	@Override
	public void init() {
		// Nothing to do
	}
	
	public void setContent(AboutBean aboutBean){
		about.setBody(aboutBean.getBody());
		about.setTitle(aboutBean.getTitle());
		introduction.setIntroduction(aboutBean.getIntroduction());
	}

	@Override
	protected Widget createWidget() {
		about = new AboutWidget();
		introduction = new IntroductionWidget();		
		
		HorizontalPanel hPanel = new HorizontalPanel();
		hPanel.add(about);
		hPanel.add(introduction);
		
		Button button = new Button("Go back to welcome page");
		button.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				Event e = new Event(GO_TO_WELCOME_PAGE, null);
				controller.handleEvent(e);
			}

		});

		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.add(hPanel);
		mainPanel.add(button);
		
		return mainPanel;
	}

}
